﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="adminpower.aspx.cs" Inherits="UI.system.page.admin.adminpower" %>
<%@ Import Namespace="Model" %>
<%@ Import Namespace="DAL" %>
<%@ Import Namespace="Common" %>
<div style="margin: 15px;">
	<form id="userpower" class="layui-form" style="padding-left:0px;">
        <%foreach(MenuInfo menu in parentlist){
              List<MenuInfo> childlist = menulist.Where(x => x.ParentID == menu.ID).ToList();
        %>
        <fieldset id="oa_power" class="layui-elem-field site-demo-button">
          <legend><input type="checkbox" name="power" lay-skin="primary" title="<%=menu.Name %>" value="menu-<%=menu.ID %>" <%=power.Contains("menu-"+menu.ID)?"checked":""%>></legend>
          <div>
                <input type="checkbox" name="allchoose" lay-filter="allchoose" lay-skin="primary" title="全选" value="all-<%=menu.ID %>" <%=power.Contains("all-"+menu.ID)?"checked":""%>>
          </div>
          <%foreach(MenuInfo child in childlist){
                string[] btns=child.Btns.Split(',');
          %>
          <div>
                <input type="checkbox" name="power" lay-skin="primary" title="<%=child.Name %>" value="menu-<%=child.ID %>" <%=power.Contains("menu-"+child.ID)?"checked":"" %>>
                <%foreach(string btnid in btns){
                      if(btnid!=""){
                      BtnsInfo btn= B.Instance<BtnsInfo>(btnslist.FirstOrDefault(x=>x.ID==DataConvert.ToInt(btnid)));
                %>
                <input type="checkbox" name="power" lay-skin="primary" title="<%=btn.Name %>" value="btns-<%=child.ID %>-<%=btnid %>" <%=power.Contains("btns-"+child.ID+"-"+btnid)?"checked":"" %>>
                <%}} %>
          </div>
          <%} %>
        </fieldset>
        <%} %>
		<a lay-filter="save" lay-submit style="display: none;"></a>
	</form>
</div>
<script>
    form.on('checkbox(allchoose)', function (data) {
        var child = $(data.elem).parent().parent().find('input[type="checkbox"]');
        child.each(function (index, item) {
            item.checked = data.elem.checked;
        });
        form.render('checkbox');
    });
</script>